<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // 需求，函数接收一个布尔类型参数，表示该颜色的格式是十六进制还是rgb格式
        function getRandomColor(flag) {


            if (flag) {
                // 如果是true，则返回#ffffff
                let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
                let str = '#'
                for (let i = 1; i <= 6; i++) {
                    let random = Math.floor(Math.random() * arr.length);
                    str += arr[random]
                }
                return str;
            } else {
                // 如果是false，则返回rgb(255，255，255)
                let r = Math.floor(Math.random() * 256)
                let g = Math.floor(Math.random() * 256)
                let b = Math.floor(Math.random() * 256)
                return `rbg(${r},${g},${b})`;

            }
        }

        console.log(getRandomColor(false));
        console.log(getRandomColor(true));

    </script>
</body>

</html>